<!DOCTYPE html>
<html>
<head>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" type="text/css" href="/static/layui/css/layui.css" media="all">
    <script type="text/javascript" src="/static/layui/layui.js"></script>
    <style type="text/css">
        .header span{background:#009688;margin-left:5px;padding:10px;color:#ffffff;}
        .header div{border-bottom:solid 2px #009688;margin-top: 8px;}
        .header button{float:right;margin-top:-5px;margin-left: 5px;}
    </style>
</head>
<body style="padding:10px; box-sizing: border-box;">
<div class="header">
    <span>备份数据库列表</span>
    <button type="button" class="layui-btn layui-btn-sm" id="up">
        <i class="layui-icon layui-icon-upload-circle"></i>上传</button>
    <button type="button" class="layui-btn layui-btn-sm" onclick="add()">
        <i class="layui-icon layui-icon-addition"></i>备份</button>
    <div></div>
</div>
<table class="layui-table">
    <thead>
    <tr>
        <th>文件名</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody>
    {foreach($lists as $lists_v)}
    <tr>
        <td>{$lists_v}</td>
        <td>
            <button type="button" class="layui-btn layui-btn-xs" onclick="re('{$lists_v}')">恢复</button>
            <button type="button" class="layui-btn layui-btn-xs" onclick="down('{$lists_v}')">下载</button>
            <button type="button" class="layui-btn layui-btn-xs" onclick="del('{$lists_v}')">删除</button>
        </td>
    </tr>
    {/foreach}
    </tbody>
</table>
</body>
<script type="text/javascript">
    layui.use(['layer','form','upload'], function(){
        $ = layui.jquery;
        layer = layui.layer;
        form = layui.form;
        upload = layui.upload;

        upload.render({
            elem: '#up',
            url: '/upsql/up/',
            accept:'file',
            done: function(res){
                //上传完毕回调
                if (res.code==0) {
                    layer.msg(res.msg,{"icon":1});
                    setTimeout(function () {
                        location.reload();
                    },1000)
                } else {
                    layer.msg(res.msg,{"icon":2});
                }
            },
            error: function(){
                //请求异常回调
            }
        });
    });
    function add(){
        layer.open({
            title:'创建',
            content: '是否创建备份？',
            shade:0.3,
            btn: ['确认', '取消'],
            yes: function(){
                $.get('/upsql/add',
                    function(res){
                        console.log(res);
                        if (res.code==0) {
                            layer.msg(res.msg,{"icon":1});
                            setTimeout(function () {
                                window.location.reload();
                            },1000)
                        } else {
                            layer.msg(res.msg,{"icon":2});
                        }
                    }, "json");
            }
        })
    }

    function re(filename){
        console.log(filename);
        layer.open({
            title:'恢复',
            content: '是否恢复备份？',
            shade:0.3,
            btn: ['确认', '取消'],
            yes: function(){
                $.get('/upsql/re?filename='+filename,
                    function(res){
                        console.log(res);
                        if (res.code==0) {
                            layer.msg(res.msg,{"icon":1});
                            setTimeout(function () {
                                window.location.reload();
                            },1000)
                        } else {
                            layer.msg(res.msg,{"icon":2});
                        }
                    }, "json");
            }
        })
    }
    function down(filename){
        window.open("./updata/"+filename);
    }
    function del(filename){
        layer.open({
            title:'删除',
            content: '是否删除备份？',
            shade:0.3,
            btn: ['确认', '取消'],
            yes: function(){
                $.get('/upsql/del?filename='+filename,
                    function(res){
                        console.log(res);
                        if (res.code==0) {
                            layer.msg(res.msg,{"icon":1});
                            setTimeout(function () {
                                location.reload();
                            },1000)
                        } else {
                            layer.msg(res.msg,{"icon":2});
                        }
                    }, "json");
            }
        })
    }
</script>
</html>